package cn.edu.zjgsu.ito.service;


import java.util.List;

import cn.edu.zjgsu.ito.model.CourseModel;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public class CourseEndService extends Service {
	/*
	 * 张虎涛
	 * 2016/06/01
	 */
	public String CourseEndate(String courseName,String termValue) {
		try {
			
			Record record=Db.findFirst(CourseModel.dao.selectCourseEndSql,courseName,termValue);
            if(record==null){
                return "none";
            }else{
                return record.getStr("endDate");
            }
			
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}

	}
	
	public boolean CEchange(String changTime,String changStartTime,String changEndTime,String now) {
		try {			
			//Db.update("update  course_end set endDate=? where (endDate between ? and ?) and (endDate>=?)",changTime,changStartTime,changEndTime,now);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}

	}
    
    public boolean checkCourseEnd(String termValue,String courseName,String courseNo) {
		try {			
			boolean tf;
            tf = Db.findFirst("select * from course_end where termValue=? and courseName=? and courseNo=?",termValue,courseName,courseNo)!=null;
			return tf;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
    
    public boolean insertCourseEnd(Record record) {
		try {			
            boolean tf=false;
		    tf=Db.save("course_end", record);
			return tf;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public boolean singleChange(String termValue,String courseName,String courseNo,String changTime) {
		try {			
			boolean tf=Db.update("update  course_end set endDate=? where termValue=? and  courseName=? and courseNo=?",changTime,termValue,courseName,courseNo)!=0;
			return tf;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
}
